package com.llgz.hotelmanageapi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.llgz.hotelmanageapi.common.CommonResult;
import com.llgz.hotelmanageapi.pojo.DO.*;
import com.llgz.hotelmanageapi.pojo.DO.RoomInfo;
import com.llgz.hotelmanageapi.pojo.DTO.RoomInfoDTO;
import com.llgz.hotelmanageapi.service.impl.RoomInfoServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 客房信息 前端控制器
 * </p>
 *
 * @author Bernie_fang
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/roomInfo")
@Api(tags = "客房信息管理")
@RequiresRoles(value = {"root", "admin", "manager", "reception"}, logical = Logical.OR)
public class RoomInfoController {
    @Autowired
    RoomInfoServiceImpl roomInfoService;

    /**
     * @MethodName addRoomInfo
     * @Params * @param RoomInfo
     * @Description 添加
     * @Return CommonResult
     */
    @PostMapping("/addRoomInfo")
    @ApiOperation(value = "添加", response = CommonResult.class, httpMethod = "POST")
    public CommonResult addRoomInfo(@RequestBody RoomInfo roomInfo){
        boolean save = roomInfoService.save(roomInfo);
        return CommonResult.successResponse(save);
    }

    /**
     * @MethodName getRoomInfoList
     * @Params * @param RoomInfo
     * @Description 查找全部
     * @Return CommonResult
     */
    @PostMapping("/getRoomInfoList")
    @ApiOperation(value = "查找", response = CommonResult.class, httpMethod = "POST")
    public CommonResult getRoomInfoList(@RequestBody RoomInfoDTO roomInfoDTO){
        IPage<RoomInfo> page = roomInfoService.getRoomInfoWithPage(roomInfoDTO);
        return CommonResult.successResponse(page);
    }

    @PostMapping("/getRoomInfoById")
    @ApiOperation(value = "查找(Id)", response = CommonResult.class, httpMethod = "POST")
    public CommonResult getRoomInfoById(@RequestParam String id){
        RoomInfo category = roomInfoService.getOne(new QueryWrapper<RoomInfo>().eq("id", id));
        return CommonResult.successResponse(category);
    }
    @GetMapping("/getRoomInfoByRoomId")
    @ApiOperation(value = "查找(Id)", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getRoomInfoByRoomId(@RequestParam String id){
        RoomInfo category = roomInfoService.getOne(new QueryWrapper<RoomInfo>().eq("room_id", id));
        return CommonResult.successResponse(category);
    }
    /**
     * @MethodName updateRoomInfo
     * @Params * @param RoomInfo
     * @Description 查空房
     * @Return CommonResult
     */
    @GetMapping("/getRoomInfoByRoomType")
    @ApiOperation(value = "查空房", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getRoomInfoByRoomType(@RequestParam Integer roomType){
        QueryWrapper<RoomInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("room_type", roomType).eq("room_status", 0).orderByAsc("room_id").last("limit 10");
        
        List<RoomInfo> list = roomInfoService.list(wrapper);
        return CommonResult.successResponse(list);
    }


    /**
     * @MethodName updateRoomInfo
     * @Params * @param RoomInfo
     * @Description 更新
     * @Return CommonResult
     */

    @PostMapping("/updateRoomInfo")
    @ApiOperation(value = "更新", response = CommonResult.class, httpMethod = "POST")
    public CommonResult updateRoomInfo (@RequestBody RoomInfo roomInfo){
        boolean b = roomInfoService.updateById(roomInfo);
        return CommonResult.successResponse(b);
    }

    /**
     * @MethodName deleteRoomInfo
     * @Params * @param RoomInfo
     * @Description 删除（多选）
     * @Return CommonResult
     */
    @PostMapping("/deleteRoomInfo")
    @ApiOperation(value = "删除（多选）", response = CommonResult.class, httpMethod = "POST")
    public CommonResult deleteRoomInfo (@RequestBody List<String> id){
        boolean b = roomInfoService.removeByIds(id);
        return CommonResult.successResponse(b);
    }

    @GetMapping("/getRoomId")
    @ApiOperation(value = "查询全部信息", response = CommonResult.class, httpMethod = "POST")
    public CommonResult getRoomId(){
        List<RoomInfo> list = roomInfoService.list();
        return CommonResult.successResponse(list);
    }

}

